<template>
  <div>
    <eHeaderAdmin :query="query" type="admin" :sup-this="supThis" />
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" height="500">
      <el-table-column :show-overflow-tooltip="true" prop="serviceproviderName" label="所属服务商" />
      <el-table-column :show-overflow-tooltip="true" prop="name" label="姓名" />
      <!--<el-table-column :show-overflow-tooltip="true" prop="username" label="账号" />-->
      <el-table-column :show-overflow-tooltip="true" prop="cellphone" label="手机号" />
      <el-table-column :show-overflow-tooltip="true" prop="isManager" label="角色">
        <template slot-scope="scope">
          {{ scope.row.isManager === 1 ? '超级管理员' : '普通管理员' }}
        </template>
      </el-table-column>
      <el-table-column v-if="checkPermission(['ADMIN','TSERVICEPROVIDERPERSON_ALL','TSERVICEPROVIDERPERSON_EDIT','TSERVICEPROVIDERPERSON_DELETE'])" label="操作" width="180px" align="center">
        <template slot-scope="scope">
          <el-button v-permission="['ADMIN','TSERVICEPROVIDERPERSON_ALL','TSERVICEPROVIDERPERSON_EDIT']" size="mini" type="primary" icon="el-icon-more" @click="handleShowDetail(scope.row)" />
          <el-button v-permission="['ADMIN','TSERVICEPROVIDERPERSON_ALL','TSERVICEPROVIDERPERSON_EDIT']" size="mini" type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)" />
          <el-popover
            :ref="scope.row.id"
            v-permission="['ADMIN','TSERVICEPROVIDERPERSON_ALL','TSERVICEPROVIDERPERSON_DELETE']"
            placement="top"
            width="180"
          >
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="handleDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" style="margin-left: 10px;" />
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
    <AddAdmin :data="formData" :type="type" :visible="addVisible" @cancel="handleClose" />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { deleteManager } from '@/api/tServiceproviderPerson';
import { parseTime } from '@/utils/index'
import eHeaderAdmin from './headerAdmin'
import AddAdmin from './addAdmin'

export default {
  components: { eHeaderAdmin, AddAdmin },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      supThis: this,
      formData: {},
      type: '',
      addVisible: false
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    handleClose() {
      this.addVisible = false
      this.formData = {}
    },
    beforeInit() {
      this.url = 'api/tServiceproviderManager'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      const query = this.query
      // const type = query.type
      // const value = query.value
      // if (type && value) { this.params[type] = value }
      if (query.personName) {
        this.params['name'] = query.personName
      }
      if (query.phone) {
        this.params['cellphone'] = query.phone
      }
      if (query.serviceproviderName) {
        this.params['serviceproviderName'] = query.serviceproviderName
      }
      return true
    },
    handleShowDetail(row) {
      this.addVisible = true;
      this.type = 'detail';
      this.formData = row;
    },
    handleAdd() {
      this.addVisible = true;
      this.formData = {};
      this.type = 'add';
    },
    handleEdit(row) {
      this.addVisible = true;
      this.type = 'edit';
      this.formData = row;
    },
    handleDelete(id) {
      deleteManager(id).then(() => {
        this.$refs[id].doClose();
        this.init();
      });
    }
  }
}
</script>

<style lang='scss' scoped>

</style>
